//
//  UUWalletWithdrawVC.m
//  UUCharterSupplier
//
//  Created by ZhangAo on 23/02/2018.
//  Copyright © 2018 UUCharter. All rights reserved.
//

#import "UUWalletWithdrawVC.h"
#import "UUHybridManager+CharterSupplier.h"
#import "UUUserManager.h"
#import "UUWalletManager.h"
#import "UUWalletApplicationSuccessVC.h"

@interface UUWalletWithdrawVC ()

@end

@implementation UUWalletWithdrawVC

- (void)viewDidLoad {
    self.editable = YES;
    
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSString *)fullName {
    return @"提现至";
}

- (NSURLRequest *)editRequest {
    return GetHybridManager().withdrawURLRequest;
}

- (NSDictionary *)previewFields {
    return @{
             @"account_money" : GetUserManager().fetchUserInfo.withdrawMoney
             };
}

- (void)addOrUpdate:(NSDictionary *)data {
    UUWalletAccountType accountType = [data[@"account_type"] integerValue];
    NSString *name = data[@"name"];
    NSString *account = data[@"account"];
    NSNumber *money = data[@"money"];
    NSString *bankName = nil;
    NSString *depositBank = nil;
    
    if (accountType == UUWalletAccountTypeUnionPay) {
        bankName = data[@"bank_name"];
        depositBank = data[@"deposit_bank"];
    }
    
    WEAK_SELF();
    ShowIndicator();
    [GetWalletManager() asyncWithdrawWithAccountType:accountType
                                                name:name
                                             account:account
                                               money:[money unsignedIntegerValue]
                                            bankName:bankName
                                         depositBank:depositBank
                                       completeBlock:^(NSError *error) {
                                           if (error == nil) {
                                               HideIndicatorInView(weakSelf.view);
                                               
                                               NSMutableArray<UIViewController *> *viewControllers = [weakSelf.navigationController.viewControllers mutableCopy];
                                               [viewControllers removeLastObject];
                                               [viewControllers addObject:[UUWalletApplicationSuccessVC instanceOfAppropriate]];
                                               
                                               [weakSelf.navigationController setViewControllers:viewControllers animated:YES];
                                           } else {
                                               ShowTipsOnView(error.localizedDescription, weakSelf.view);
                                           }
                                       }];
}

@end
